<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>品牌列表</title>
    <script src="js/axios.min.js"></script>
</head>
<body onload="getBrandList()">
<a href="addBrand.html"><input type="button" value="新增"></a><br>
<hr>
<table id="brandTable" border="1" cellspacing="0" width="100%">
    <tr>
        <th>序号</th>
        <th>品牌名称</th>
        <th>企业名称</th>
        <th>排序</th>
        <th>品牌介绍</th>
        <th>状态</th>
        <th>操作</th>
    </tr>


</table>
</body>

<script type="text/javascript">

    function getBrandList(){

        //1.获取表格对象
        var table = document.getElementById("brandTable");

        //2.发送ajax请求
        axios({
            url:'/brand-case/brandAll',
            method:'GET'
        }).then((response)=>{

            //3.获取响应数据
            var brands = response.data;
            for(let i = 0; i < brands.length;++i)
            {
                let brand = brands[i];
                let tr = '<tr align="center">\n' +
                    '<td>'+(i+1)+'</td>\n' +
                    '<td>'+brand.brandName+'</td>\n' +
                    '<td>'+brand.companyName+'</td>\n' +
                    '<td>'+brand.ordered+'</td>\n' +
                    '<td>'+brand.description+'</td>\n' +
                    '<td>'+brand.status+'</td>\n' +
                    '\n' +
                    '<td><a href="addBrand.html?id='+brand.id+'">修改</a> <input type="button" value="删除" onclick=\"deleteBrand('+brand.id+')\"> </td>\n' +
                    '</tr>';

                table.innerHTML += tr;
            }
        })

    }


    function deleteBrand(id) {

        axios({
            url: '/brand-case/brandDel?id='+id,
            method: 'GET'
        }).then((response) => {

            if(response.data)
            {
                getBrandList();
            }else
            {
                alert("删除失败");
            }

        })
    }

</script>
</html>